package cn.gwm.flink.streaming.dwm.charge.facory;

import cn.gwm.flink.streaming.dwm.charge.template.*;
import cn.gwm.flink.streaming.dwm.charge.model.ChargeStateEnum;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName ChargeStateHandleFactoy
 * @Description 充电状态处理类工厂
 * @Author LiangGuang
 * @Date 2023/05/11 18:20
 */
@Slf4j
public class ChargeStateFactory {
    private static final Map<String, ChargeStateModel> stateModelMap = new HashMap<>();

    static {
        // 将 ChargeStateStrategy 子类 添加进来
        stateModelMap.put(ChargeStateEnum.END.getState(), new PhysicsChargeState());
        stateModelMap.put(ChargeStateEnum.UNABLE.getState(), new UnableChargeState());
        stateModelMap.put(ChargeStateEnum.WAIT.getState(), new ReadyChargeState());
        stateModelMap.put(ChargeStateEnum.FULLY.getState(), new FullyChargeState());
        stateModelMap.put(ChargeStateEnum.SUSPEND.getState(), new SuspendChargeState());
        stateModelMap.put(ChargeStateEnum.CHARGING.getState(), new ChargingChargeState());
        stateModelMap.put(ChargeStateEnum.LOGIC_BREAK.getState(), new LogicBreakChargeState());
        stateModelMap.put(ChargeStateEnum.FAULT.getState(), new FaultChargeState());
        stateModelMap.put(ChargeStateEnum.DELAY.getState(), new DelayChargeState());
        stateModelMap.put(ChargeStateEnum.ERROR.getState(), new ErrorChargeState());
        stateModelMap.put(ChargeStateEnum.OTHER.getState(), new OtherChargeState());
        stateModelMap.put(ChargeStateEnum.PREHEAT.getState(), new PreheatChargeState());
        // 暂时 ：充电且加热当做充电处理
        stateModelMap.put(ChargeStateEnum.CHARGING_HEATING.getState(), new ChargingChargeState());

        stateModelMap.put(ChargeStateEnum.UNKNOWN.getState(), new UnkowonChargeState());


    }

    public static ChargeStateModel getStateHandle(ChargeStateEnum state) {
        if (!stateModelMap.containsKey(state.getState())) {
//            throw new RuntimeException("There is no solution for the " + state.getState() + " type. " +
//                    "Please confirm that the current status is correct or supplement the corresponding solution.");
            log.error("There is no solution for the " + state.getState() + " type. Please confirm that the current status is correct or supplement the corresponding solution.");
            return stateModelMap.get(ChargeStateEnum.UNKNOWN.getState());
        }
        return stateModelMap.get(state.getState());
    }

}
